<?php
namespace app\web\admin;

use app\admin\controller\Admin;

/**
 * 轮播管理（后台）
 * @package
 */
class Base extends Admin 
{
    public $role_id;

	protected function initialize()
    {
    	parent::initialize();
        $this->role_id = session('user_auth.role');
    }

    final protected function setImgPath($text='',$flag = false){
    	if(!$text) return '';
    	if($flag){
        	return str_replace('src="/', 'src="' . config("api.image_path") . "/", $text);
    	}
        $text = explode(',',$text);
        $image_path = config('api.image_path');
        foreach ($text as $key => $value) {
            $text[$key] = $image_path.get_file_path($value);
        }
        return implode(',',$text);
    }
    /**
     * 表格中显示多张图片
     * [tableImg description]
     * @param  [type] $item  [description] 数组
     * @param  [type] $key   [description]
     * @param  [type] $field [description]
     * @return [type]        [description]
     */
    final protected function tableImg($item,$key,$field){
        if($item[$field]){
            $html = '<div class="js-gallery">';
            $picture = is_array($item[$field]) ? $item[$field] : explode(',', $item[$field]);
            foreach ($picture as $k => $val) {
                $html .= '<img class="image" style="margin:0 2px;" data-original="'.$val.'" src="'.$val.'">';
            }
            $item[$field] = $html.'</div>';
        }
        return $item;
    }

    final protected function getOrderNo(){
        $snowid = new \Godruoyi\Snowflake\Snowflake;
        $snowid->setStartTimeStamp(strtotime(date("2020-10-01")) * 1000);
        return date("Y") . $snowid->id();
    }

    final protected function getCss(){
        $css = <<<EOF
           <style>
                .check_status0{background:red!important;color:#fff!important;}
           </style>
EOF;
        return $css;
    }
}	
